// KMP算法
function kmpserach(text, pattern) {
    let i = 0
    let j = 0
    let next = getnext(pattern)
    while (i < text.length) {
        if (text[i] === pattern[j]) {
            i++
            j++
        }
        if (j === pattern.length) {
            return i - j
        } else if (i < text.length && text[i] !== pattern[j]) {
            if (j !== 0) {
                j = next[j]
            }
            else {
                i++
            }
        }
    }
    return -1
}